package com.xxg.renrenorder.strategy;

import com.xxg.renrencommon.exception.OrderManagerException;
import com.xxg.renrencommon.exception.exceptionenum.OrderExceptionCodeCodeEnum;
import com.xxg.renrenorder.dao.AfterSalesOrderInfoDao;
import com.xxg.renrenorder.dao.bean.AfterSalesOrderInfo;
import com.xxg.renrenorder.dao.bean.OrderMasterInfo;

/**
 * 售后策略上下文
 *
 * @author szj
 * @date 2021/12/17
 */
public class AfterSalesStrategyContext {
    private final AfterSalesOrderInfoDao afterSalesOrderInfoDao;
    private final Integer afterSalesType;

    public AfterSalesStrategyContext(AfterSalesOrderInfoDao afterSalesOrderInfoDao, Integer afterSalesType) {
        this.afterSalesOrderInfoDao = afterSalesOrderInfoDao;
        this.afterSalesType = afterSalesType;
    }

    private AfterSalesStrategy getStrategy(Integer afterSalesType) throws OrderManagerException {
        AfterSalesStrategy afterSalesStrategy;
        switch (afterSalesType) {
            case 1:
                // 仅退款
            case 2:
                // 未收到货退款
                afterSalesStrategy = new ReturnProductStrategy();
                break;
            case 3:
                // 退货退款
                afterSalesStrategy = new ReturnMoneyAndProductStrategy();
                break;
            case 4:
                // 维修
                afterSalesStrategy = new RepairProductStrategy();
                break;
            case 5:
                afterSalesStrategy = new ChangeProductStrategy();
                // 换货
                break;
            case 6:
                afterSalesStrategy = new ReplacementStrategy();
                // 补寄
                break;
            case 7:
                afterSalesStrategy = new ReplacePartStrategy();
                // 补寄零件
                break;
            default:
                throw new OrderManagerException(OrderExceptionCodeCodeEnum.UN_SUPPORT_AFTER_SALES_TYPE);
        }
        afterSalesStrategy.setAfterSalesOrderInfoDao(afterSalesOrderInfoDao);
        return afterSalesStrategy;
    }

    public AfterSalesStrategy handlerAfterSalesOrderInfo(AfterSalesOrderInfo afterSalesOrderInfo, OrderMasterInfo orderMasterInfo, boolean isApply) throws OrderManagerException {
        AfterSalesStrategy strategy = getStrategy(afterSalesType);
        strategy.handlerAfterSalesOrderInfo(afterSalesOrderInfo, orderMasterInfo, isApply);
        return strategy;
    }
}
